package com.yxt.admin.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.yxt.admin.entity.SysTenantEntity;
import com.yxt.admin.mapper.SysTenantMapper;
import com.yxt.admin.service.SysTenantService;
import com.yxt.admin.vo.SelectedVO;
import com.yxt.common.utils.ajax.PageUtils;
import com.yxt.common.utils.ajax.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yxt.admin.entity.SysTenantEntity;
import com.yxt.admin.service.SysTenantService;



/**
 * 
 *
 * @author august
 * @email 379249906@qq.com
 * @date 2020-09-10 14:02:18
 */
@RestController
@RequestMapping("/admin/tenant")
public class SysTenantController {
    @Autowired
    private SysTenantService sysTenantService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysTenantService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SysTenantEntity sysTenant = sysTenantService.getById(id);

        return R.ok().put("sysTenant", sysTenant);
    }

    @RequestMapping("/names")
    public R tenantName(){
        List<SelectedVO> tenantName = sysTenantService.getTenantName();
        return R.ok().put("data", tenantName);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SysTenantEntity sysTenant){
		//sysTenantService.save(sysTenant);
        sysTenantService.cascadeSave(sysTenant);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SysTenantEntity sysTenant){
		sysTenantService.updateById(sysTenant);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		//sysTenantService.removeByIds(Arrays.asList(ids));
        sysTenantService.cascadeDelete(Arrays.asList(ids));
        return R.ok();
    }

}
